package com.chenzhiling.study.datasource.LocalFile

import com.chenzhiling.study.datasource.FileSchema
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.sources.{BaseRelation, TableScan}
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.{Row, SQLContext}

/**
 * @Author: CHEN ZHI LING
 * @Date: 2021/8/30
 * @Description: 本地文件数据源
 */
class LocalFileRelation(override val sqlContext:SQLContext,parameter: Map[String, String])
  extends BaseRelation with TableScan{

  private val PATH: String = "path"
  override def schema: StructType = FileSchema.schema

  override def buildScan(): RDD[Row] = {
    val path: String = parameter(PATH)
    val sc: SparkContext = sqlContext.sparkContext
    new LocalFileRdd(sc,path)
  }
}
